<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="申请编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'applyNo', validatorRules.applyNo]" placeholder="请输入申请编号"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="申报日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-date    placeholder="请选择申报日期" v-decorator="[ 'declareDate', validatorRules.declareDate]" :trigger-change="true" style="width: 100%"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mesYearMonth', validatorRules.mesYearMonth]" placeholder="请输入年月"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="审批状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-dict-select-tag  type="list" v-decorator="['approveStatus', validatorRules.approveStatus]" :trigger-change="true" dictCode="mes_hr_monthly_approve_status" placeholder="请选择审批状态"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="申报理由" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'declareReason', validatorRules.declareReason]" placeholder="请输入申报理由"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<j-upload v-decorator="['fileUrl', validatorRules.fileUrl]" :trigger-change="true"></j-upload>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'remark', validatorRules.remark]" placeholder="请输入备注"></p-input>
			</p-form-item>
		  </p-col>
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesHrMonthlyEmpDeclareModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        applyNo:{rules: [{ required: true, message: '请输入申请编号!' }]},
        declareDate:{rules: [{ required: true, message: '请输入申报日期!' }]},
        mesYearMonth:{rules: [{ required: true, message: '请输入年月!' }]},
        approveStatus:{rules: [{ required: true, message: '请输入审批状态!' }]},
        declareReason:{},
        fileUrl:{},
        remark:{},
        },
        url: {
          add: '/mes-manpower/auto/mesHrMonthlyEmpDeclare/add',
          edit: '/mes-manpower/auto/mesHrMonthlyEmpDeclare/edit',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'applyNo','declareDate','mesYearMonth','approveStatus','declareReason','fileUrl','createBy','createTime','updateBy','updateTime','remark'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
				  let formData = Object.assign(this.model, values);
				  this.formData = Object.assign(this.model, values);
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

			})
		},
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'applyNo','declareDate','mesYearMonth','approveStatus','declareReason','fileUrl','createBy','createTime','updateBy','updateTime','remark'))
      },

      
    }
  }
</script>